<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <table width="680" border="0" cellspacing="0" cellpadding="0"  id="tableformDangNhap">
            <tr align="center" valign="middle" bgcolor="#FF0000">
                <td  bgcolor="#FF0000" height="30" colspan="2" class="menu1">SẢN PHẨM</td>
            </tr>
            <tr align="left" valign="middle">
                <c:choose>
                    <c:when test="${param.MaParent!=null}">
                        <td id="tdformDangNhap" height="25" colspan="2" bgcolor="#55BFFF" style="font-weight: bold">
                            <a style="text-decoration: none; color: #00C;" href="SanPhamDanhMuc.do?MaDanhMuc=${param.MaParent}&TenDanhMuc=${param.TenParent}">${param.TenParent}</a> 
                            >> ${param.TenDanhMuc}
                    </c:when>
                    <c:otherwise>
                        <td id="tdformDangNhap" height="25" colspan="2" bgcolor="#55BFFF" style="font-weight: bold">
                    ${param.TenDanhMuc}
                </td>
                    </c:otherwise>
                </c:choose>
                
            </tr>
            <tr>
                <td id="tdformDangNhap" width="70%">
                    <c:forEach var="i" begin="1" end="${soTrang}"
                               step="1" >
                        <a style="color:#00C" href="SanPhamDanhMuc.do?MaDanhMuc=${param.MaDanhMuc}&TenDanhMuc=${param.TenDanhMuc}&trang=${i}&soLuongSanPhamTrenTrang=${soLuongSanPhamTrenTrang}">${i}</a> 
                        <c:if test="${i < soTrang}" >
                            |
                        </c:if>
                    </c:forEach>
                </td>
                <td  width="30%" align="right">
                    <form name="frmSoSanPhamTrenTrang" action="SanPhamDanhMuc.do" method="get">
                        <input  name="MaDanhMuc"  type="hidden" value="${param.MaDanhMuc}" />
                        <input  name="TenDanhMuc"  type="hidden" value="${param.TenDanhMuc}" />
                        <label for="soLuongSanPhamTrenTrang">Số lượng</label>
                        <select name="soLuongSanPhamTrenTrang" onchange="submit()">
                            <c:forEach var="i" begin="1" end="5">
                                <option 
                                    <c:if test="${i*3 == soLuongSanPhamTrenTrang}" >
                                        selected="selected"
                                    </c:if>
                                    value="${i*3}">${i*3}</option>
                            </c:forEach>
                            <option
                                <c:if test="${soLuongSanPhamTrenTrang}==-1" >
                                    selected="selected"
                                </c:if>
                                value="-1">Tất cả</option>
                        </select>
                    </form>
                </td>
            </tr>
            <tr>
            <tr>
                <td colspan="2">
                    <c:if test="${dssp.size()>0}">
                    <table width="100%" border="0" cellspacing="0" cellpadding="5">
                        <c:choose>
                            <c:when test="${dssp.size()%3 ==0}" >
                                <c:set var="so_hang" value="${dssp.size()/3}"/>
                            </c:when>
                            <c:when test="${dssp.size()%3 !=0}" >
                                <c:set var="so_hang" value="${dssp.size()/3+1}"/>
                            </c:when>
                        </c:choose>
                        <c:forEach var="i" begin="0" end="${so_hang-1}" step="1">

                            <tr>
                                <c:set var="vtr_ketthuc" value="${i*3+3}"/>
                                <c:if test="${dssp.size()<i*3+3}">
                                    <c:set var="vtr_ketthuc" value="${dssp.size()}"/>
                                </c:if>
                                <c:forEach var="t" begin="${i*3}" end="${vtr_ketthuc-1}" step="1">
                                    <c:set var="sp" value="${dssp.get(t)}"/>
                                    <!--Bắt đầu 1 hàng-->
                                    <td class="sanpham_cell" width="33%" align="center" valign="top">
                                        <table border="0" width="100%">
                                            <tr>
                                                <td class="tieude_cell" height="40px">
                                                    <b><a href="index.jsp?MainContent=ChiTietSanPham&MaSanPham=${sp.maSanPham}" title="Click xem chi tiết sản phẩm" class="sanpham_link">
                                                            ${sp.tenSanPham}</a></b>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="hinh_cell">
                                                    <a href="index.jsp?MainContent=ChiTietSanPham&MaSanPham=${sp.maSanPham}">
                                                        <img src="${sp.hinhAnh}" width="150" height="125" alt="Click để xem chi tiết"
                                                             />
                                                    </a>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" clas="gia_cell">
                                                    <fmt:formatNumber type="currency" value="${sp.donGia}" />

                                                </td>
                                            </tr>
                                            <tr >
                                                <td  style="padding-left: 65px;">
                                                    <c:forEach var="p" begin="1" end="${sp.diemDanhGia}" step="1">
                                                        <div id="star-${p}" class="rating-on"></div>
                                                    </c:forEach>
                                                    <c:forEach var="p" begin="${sp.diemDanhGia}" end="4" step="1">
                                                        <div id="star-${p}" class="rating-off"></div>
                                                    </c:forEach>

                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" clas="gia_cell" style="background-color:#cad9ed">
                                                    <a href="GioHang.do?Action=DatMua&MaSanPham=${sp.maSanPham}&SoLuong=1" style="color:#0762A2;"><input  type="button" value="" style="background-image:url(images/AddToCart_new.jpg); background-repeat:no-repeat; width:150px; height:30px;" /></a>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                    <!--Những o ko co san pham-->

                                </c:forEach>
                                <c:forEach var="t" begin="${vtr_ketthuc}" end="${i*3+3}" step="1">

                                    <td class="sanpham_cell" width="33%" align="center" valign="top">&nbsp;</td>
                                </c:forEach>
                                <!--Kết thúc 1 hàng-->
                            </tr>
                        </c:forEach>
                    </table>
                    </c:if>
                </td>
            </tr>  
        </tr>              
    </table>
</body>
</html>
